from rest_framework.generics import ListAPIView
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.viewsets import ModelViewSet
from rest_framework.permissions import IsAdminUser
from goods.models import SKUImage, SKU
from meiduo_admin.serializers.skus import SKUImageSerializer, SKUSimpleSerializer


class SKUImageViewSet(ModelViewSet):
    permission_classes = [IsAdminUser]
    queryset = SKUImage.objects.all()
    serializer_class = SKUImageSerializer
    lookup_value_regex = '\d+'
    # 获取图片数据:GET /meiduo_admin/skus/images/ ==> list
    # 新增数据:POST/meiduo_admin/skus/images/ ===>create
    # 获取指定图片数据:GET/meiduo_admin/skus/images/(?P<pk>\d+)/===>retrieve
    # 修改指定图片数据:PUT/meiduo_admin/kus/images/(?P<pk>\d+)/===>update
    # 指定图片数据删除:delete/meiduo_admin/kus/images/(?P<pk>\d+)/===>destroy


class SKUSimpleView(ListAPIView):
    permission_classes = [IsAdminUser]

    '''
    获取sku简单数据
    1.查询数据库获取所有sku数据
    2.将sku数据序列化返回
    '''
    # 1.查询数据库获取所有sku数据
    queryset = SKU.objects.all()

    # 2.将sku数据序列化返回
    serializer_class = SKUSimpleSerializer

    # 注：关闭分页
    pagination_class = None
